package com.example.week10_advanceui2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TabHost;

public class GridViewActivity extends AppCompatActivity {

    //用于填充GridView的图片
    private int[] imageIds={R.drawable.img_1,R.drawable.img_2,R.drawable.img_3,R.drawable.img_4,R.drawable.img_5,R.drawable.img_6,R.drawable.img_7,R.drawable.img_8,R.drawable.img_9};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_view);

        GridView gridView=(GridView)findViewById(R.id.gridview);

        ImageAdapter imageAdapter=new ImageAdapter(this,imageIds);

        gridView.setAdapter(imageAdapter);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                Intent intent=new Intent();
                switch (position)
                {
                    case 1: //备忘录(Menu)
                        intent.setClass(GridViewActivity.this,TextBookActivity.class);
                        startActivity(intent);
                        break;
                    case 4://备忘录(ContextMenu)
             intent.setClass(GridViewActivity.this,TextBookContextMenuActivity.class);
                        startActivity(intent);
                        break;

                    case 6://(校园那些事)
                        intent.setClass(GridViewActivity.this,TabHostActivity.class);
                        startActivity(intent);
                        break;

                    case 8://新闻系统（fragment）
                    intent.setClass(GridViewActivity.this, NewsActivity.class);
                    startActivity(intent);
                    break;
                }
            }
        });
    }
}
